<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    <link rel="canonical" href="http://xiejm.com/MySQL/MySQL--Source_Install.html">
    
    
    <title>MySQL 5.6基于Linux源码编译安装 | XieJM&#39;s Blog | 建立博客是为了记录工作经验以及生活点滴,也是将知识和经验分享给需要的朋友，希望对你有帮助！</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#00bcd4">
    
    
    <meta name="keywords" content="MySQL">
    <meta name="description" content="MySQL可以通过YUM或其他安装包快速安装，也可以下载源代码编译安装。从源代码编译安装MySQL是有好处，比如可以指定编译生产参数、优化编译、指定安装位置等。 本文的主要内容：  获取源码 系统配置、编译和安装 配置MySQL">
<meta name="keywords" content="MySQL">
<meta property="og:type" content="article">
<meta property="og:title" content="MySQL 5.6基于Linux源码编译安装">
<meta property="og:url" content="http://xiejm.com/MySQL/MySQL--Source_Install.html">
<meta property="og:site_name" content="XieJM&#39;s Blog">
<meta property="og:description" content="MySQL可以通过YUM或其他安装包快速安装，也可以下载源代码编译安装。从源代码编译安装MySQL是有好处，比如可以指定编译生产参数、优化编译、指定安装位置等。 本文的主要内容：  获取源码 系统配置、编译和安装 配置MySQL">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2017-10-04T13:43:52.487Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="MySQL 5.6基于Linux源码编译安装">
<meta name="twitter:description" content="MySQL可以通过YUM或其他安装包快速安装，也可以下载源代码编译安装。从源代码编译安装MySQL是有好处，比如可以指定编译生产参数、优化编译、指定安装位置等。 本文的主要内容：  获取源码 系统配置、编译和安装 配置MySQL">
    
        <link rel="alternate" type="application/atom+xml" title="XieJM&#39;s Blog" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/style.css?v=1.6.13">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">XieJM</h5>
          <a href="mailto:309469843@qq.com" title="309469843@qq.com" class="mail">309469843@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/index.html"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives/index.html"  >
                <i class="icon icon-lg icon-archives"></i>
                归档
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags/index.html"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories/index.html"  >
                <i class="icon icon-lg icon-th-list"></i>
                分类
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/xjmhz" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
      </ul>      
    </div>
    <footer class="footer">
    <p>欢迎加入我们的大数据交流群：<br>群1：258669058 群2：126181630</p>   
    <p>        
        <span><a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh"><img src="/img/cc.png"></a></span>
        
        <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-2x icon-rss-square"></i></a></span>
        
    </p>
    <p><span>XieJM &copy; 2017</span>
    </p>
    <p><span>
            
            Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
        </span>
    </p>
</footer>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">MySQL 5.6基于Linux源码编译安装</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">MySQL 5.6基于Linux源码编译安装</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-10-03T02:25:13.266Z" itemprop="datePublished" class="page-time">
  2017-10-03
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/tech/">技术</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#1-获取源码"><span class="post-toc-text">1. 获取源码</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#2-系统配置"><span class="post-toc-text">2.系统配置</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#2-1-检查系统是否有MySQL"><span class="post-toc-text">2.1 检查系统是否有MySQL</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#2-2-创建用户和组"><span class="post-toc-text">2.2 创建用户和组</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#2-3-创建MySQL配置文件"><span class="post-toc-text">2.3 创建MySQL配置文件</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#2-4-配置权限"><span class="post-toc-text">2.4 配置权限</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#2-5-安装"><span class="post-toc-text">2.5 安装</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#2-6-配置开机启动"><span class="post-toc-text">2.6 配置开机启动</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#2-7-启动MySQL"><span class="post-toc-text">2.7 启动MySQL</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#3-配置MySQL"><span class="post-toc-text">3.配置MySQL</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#3-1-登录"><span class="post-toc-text">3.1 登录</span></a></li></ol></li></ol>
        </nav>
    </aside>
    
<article id="post-MySQL/MySQL--Source_Install"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">MySQL 5.6基于Linux源码编译安装</h1>
        <div class="post-meta">
            <time class="post-time" title="2017-10-03 10:25:13" datetime="2017-10-03T02:25:13.266Z"  itemprop="datePublished">2017-10-03</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/tech/">技术</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>MySQL可以通过YUM或其他安装包快速安装，也可以下载源代码编译安装。从源代码编译安装MySQL是有好处，比如可以指定编译生产参数、优化编译、指定安装位置等。</p>
<p>本文的主要内容：</p>
<ol>
<li>获取源码</li>
<li>系统配置、编译和安装</li>
<li>配置MySQL</li>
</ol>
<a id="more"></a>
<h2 id="1-获取源码"><a href="#1-获取源码" class="headerlink" title="1. 获取源码"></a>1. 获取源码</h2><p>可以在以下页面找到</p>
<p><a href="http://dev.mysql.com/downloads/mysql/" target="_blank" rel="external">http://dev.mysql.com/downloads/mysql/</a></p>
<p>MySQL的源文件被打包为.tar.gz或.zip格式。在本例中，我下载的源代码文件为’mysql-5.6.23.tar.gz’。</p>
<p>可以使用tar命令解压文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@hadoop001 ~]<span class="comment">#  tar -zxvf mysql-5.6.23.tar.gz -C /usr/local/</span></div><div class="line">[root@hadoop001 ~]<span class="comment"># cd /usr/local/</span></div><div class="line">[root@hadoop001 <span class="built_in">local</span>]<span class="comment"># mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql</span></div></pre></td></tr></table></figure>
<h2 id="2-系统配置"><a href="#2-系统配置" class="headerlink" title="2.系统配置"></a>2.系统配置</h2><h3 id="2-1-检查系统是否有MySQL"><a href="#2-1-检查系统是否有MySQL" class="headerlink" title="2.1 检查系统是否有MySQL"></a>2.1 检查系统是否有MySQL</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># ps -ef|grep mysqld</span></div><div class="line">root      2493  2423  0 19:48 pts/3    00:00:00 grep mysqld</div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># rpm -qa |grep -i mysql</span></div></pre></td></tr></table></figure>
<p>如果有系统自带的MySQL卸载之</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># rpm -qa |grep mysql</span></div><div class="line">mysql-libs-5.1.73-5.el6_6.x86_64</div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64</span></div></pre></td></tr></table></figure>
<h3 id="2-2-创建用户和组"><a href="#2-2-创建用户和组" class="headerlink" title="2.2 创建用户和组"></a>2.2 创建用户和组</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">Create group and user</div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># groupadd -g 101 dba</span></div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># useradd -u 520 -g dba -G root -md /usr/local/mysql mysqladmin</span></div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># id mysqladmin</span></div><div class="line">uid=520(mysqladmin) gid=101(dba) groups=101(dba),0(root)</div><div class="line"></div><div class="line"><span class="comment">#设置mysqladmin用户密码</span></div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># passwd mysqladmin</span></div><div class="line">Changing password <span class="keyword">for</span> user mysqladmin.</div><div class="line">New UNIX password:</div><div class="line">BAD PASSWORD: it is too simplistic/systematic</div><div class="line">Retype new UNIX password:</div><div class="line">passwd: all authentication tokens updated successfully.</div></pre></td></tr></table></figure>
<p>复制用户环境变量的初始配置文件至mysqladmin用户的home目录中</p>
<p>为了解决切换用户显示-bash-4.1$的问题</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># cp /etc/skel/.* /usr/local/mysql</span></div></pre></td></tr></table></figure>
<h3 id="2-3-创建MySQL配置文件"><a href="#2-3-创建MySQL配置文件" class="headerlink" title="2.3 创建MySQL配置文件"></a>2.3 创建MySQL配置文件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div></pre></td><td class="code"><pre><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># vim /etc/my.cnf</span></div><div class="line"></div><div class="line"><span class="comment">#把以下配置文件内容复制到/etc/my.cnf中</span></div><div class="line"></div><div class="line">[client]</div><div class="line">port            = 3306</div><div class="line">socket          = /usr/<span class="built_in">local</span>/mysql/data/mysql.sock</div><div class="line"></div><div class="line">[mysqld]</div><div class="line">port            = 3306</div><div class="line">socket          = /usr/<span class="built_in">local</span>/mysql/data/mysql.sock</div><div class="line">explicit_defaults_for_timestamp=<span class="literal">true</span></div><div class="line">skip-external-locking</div><div class="line">key_buffer_size = 256M</div><div class="line">sort_buffer_size = 2M</div><div class="line">read_buffer_size = 2M</div><div class="line">read_rnd_buffer_size = 4M</div><div class="line">query_cache_size= 32M</div><div class="line">max_allowed_packet = 16M</div><div class="line">myisam_sort_buffer_size=128M</div><div class="line">tmp_table_size=32M</div><div class="line"></div><div class="line">table_open_cache = 512</div><div class="line">thread_cache_size = 8</div><div class="line">wait_timeout = 86400</div><div class="line">interactive_timeout = 86400</div><div class="line">max_connections = 600</div><div class="line"></div><div class="line"><span class="comment"># Try number of CPU's*2 for thread_concurrency</span></div><div class="line"><span class="comment">#thread_concurrency = 32</span></div><div class="line"></div><div class="line"><span class="comment">#isolation level and default engine </span></div><div class="line">default-storage-engine = INNODB</div><div class="line">transaction-isolation = READ-COMMITTED</div><div class="line"></div><div class="line">server-id  = 1</div><div class="line">basedir     = /usr/<span class="built_in">local</span>/mysql</div><div class="line">datadir     = /usr/<span class="built_in">local</span>/mysql/data</div><div class="line">pid-file     = /usr/<span class="built_in">local</span>/mysql/data/hostname.pid</div><div class="line"></div><div class="line"><span class="comment">#open performance schema</span></div><div class="line"><span class="built_in">log</span>-warnings</div><div class="line">sysdate-is-now</div><div class="line"></div><div class="line">binlog_format = MIXED</div><div class="line">log_bin_trust_function_creators=1</div><div class="line"><span class="built_in">log</span>-error  = /usr/<span class="built_in">local</span>/mysql/data/hostname.err</div><div class="line"><span class="built_in">log</span>-bin=/usr/<span class="built_in">local</span>/mysql/arch/mysql-bin</div><div class="line"><span class="comment">#other logs</span></div><div class="line"><span class="comment">#general_log =1</span></div><div class="line"><span class="comment">#general_log_file  = /usr/local/mysql/data/general_log.err</span></div><div class="line"><span class="comment">#slow_query_log=1</span></div><div class="line"><span class="comment">#slow_query_log_file=/usr/local/mysql/data/slow_log.err</span></div><div class="line"></div><div class="line"><span class="comment">#for replication slave</span></div><div class="line"><span class="comment">#log-slave-updates </span></div><div class="line"><span class="comment">#sync_binlog = 1</span></div><div class="line"></div><div class="line"><span class="comment">#for innodb options </span></div><div class="line">innodb_data_home_dir = /usr/<span class="built_in">local</span>/mysql/data/</div><div class="line">innodb_data_file_path = ibdata1:500M:autoextend</div><div class="line">innodb_log_group_home_dir = /usr/<span class="built_in">local</span>/mysql/arch</div><div class="line">innodb_log_files_in_group = 2</div><div class="line">innodb_log_file_size = 200M</div><div class="line"></div><div class="line">innodb_buffer_pool_size = 2048M</div><div class="line">innodb_additional_mem_pool_size = 50M</div><div class="line">innodb_log_buffer_size = 16M</div><div class="line"></div><div class="line">innodb_lock_wait_timeout = 100</div><div class="line"><span class="comment">#innodb_thread_concurrency = 0</span></div><div class="line">innodb_flush_log_at_trx_commit = 1</div><div class="line">innodb_locks_unsafe_for_binlog=1</div><div class="line"></div><div class="line"><span class="comment">#innodb io features: add for mysql5.5.8</span></div><div class="line">performance_schema</div><div class="line">innodb_read_io_threads=4</div><div class="line">innodb-write-io-threads=4</div><div class="line">innodb-io-capacity=200</div><div class="line"><span class="comment">#purge threads change default(0) to 1 for purge</span></div><div class="line">innodb_purge_threads=1</div><div class="line">innodb_use_native_aio=on</div><div class="line"></div><div class="line"><span class="comment">#case-sensitive file names and separate tablespace</span></div><div class="line">innodb_file_per_table = 1</div><div class="line">lower_case_table_names=1</div><div class="line"></div><div class="line">[mysqldump]</div><div class="line">quick</div><div class="line">max_allowed_packet = 16M</div><div class="line"></div><div class="line">[mysql]</div><div class="line">no-auto-rehash</div><div class="line"></div><div class="line">[mysqlhotcopy]</div><div class="line">interactive-timeout</div><div class="line"></div><div class="line">[myisamchk]</div><div class="line">key_buffer_size = 256M</div><div class="line">sort_buffer_size = 256M</div><div class="line">read_buffer = 2M</div><div class="line">write_buffer = 2M</div></pre></td></tr></table></figure>
<h2 id="2-4-配置权限"><a href="#2-4-配置权限" class="headerlink" title="2.4 配置权限"></a>2.4 配置权限</h2><p>修改my.cnf文件权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># chown mysqladmin:dba /etc/my.cnf</span></div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># chmod 640 !$</span></div><div class="line">chmod 640 /etc/my.cnf</div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># ll !$</span></div><div class="line">ll /etc/my.cnf</div><div class="line">-rw-r----- 1 mysqladmin dba 2218 Sep 25 11:30 /etc/my.cnf</div></pre></td></tr></table></figure>
<p>修改mysql目录权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="comment">## 创建日志存放目录</span></div><div class="line">[root@Master ~]$ mkdir /usr/<span class="built_in">local</span>/mysql/arch</div><div class="line"></div><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># chown -R mysqladmin:dba /usr/local/mysql/</span></div></pre></td></tr></table></figure>
<h3 id="2-5-安装"><a href="#2-5-安装" class="headerlink" title="2.5 安装"></a>2.5 安装</h3><p>安装glibc</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@Master <span class="built_in">local</span>]<span class="comment"># yum install -y glibc</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@Master ~]$ su - mysqladmin</div><div class="line">[mysqladmin@Master ~]$ scripts/mysql_install_db  --user=mysqladmin --basedir=/usr/<span class="built_in">local</span>/mysql --datadir=/usr/<span class="built_in">local</span>/mysql/data </div><div class="line"></div><div class="line">WARNING: The host <span class="string">'Master'</span> could not be looked up with /usr/<span class="built_in">local</span>/mysql/bin/resolveip.</div><div class="line">This probably means that your libc libraries are not 100 % compatible</div><div class="line">with this binary MySQL version. The MySQL daemon, mysqld, should work</div><div class="line">normally with the exception that host name resolving will not work.</div><div class="line">This means that you should use IP addresses instead of hostnames</div><div class="line">when specifying MySQL privileges !</div><div class="line"></div><div class="line">Installing MySQL system tables...OK</div><div class="line"></div><div class="line">Filling <span class="built_in">help</span> tables...OK</div></pre></td></tr></table></figure>
<p>退出到root用户操作</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[mysqladmin@Master ~]$ <span class="built_in">exit</span></div><div class="line"><span class="built_in">logout</span></div></pre></td></tr></table></figure>
<h3 id="2-6-配置开机启动"><a href="#2-6-配置开机启动" class="headerlink" title="2.6 配置开机启动"></a>2.6 配置开机启动</h3><p>将服务文件拷贝到init.d下，并重命名为mysql</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@Master mysql]<span class="comment"># cp support-files/mysql.server /etc/rc.d/init.d/mysql</span></div></pre></td></tr></table></figure>
<p>修改启动文件的执行权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@Master mysql]<span class="comment"># chmod +x /etc/rc.d/init.d/mysql</span></div></pre></td></tr></table></figure>
<p>添加MySQL服务启动级别</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@Master mysql]<span class="comment"># chkconfig --del mysql</span></div><div class="line">[root@Master mysql]<span class="comment"># chkconfig --add mysql</span></div><div class="line">[root@Master mysql]<span class="comment"># chkconfig |grep mysql</span></div><div class="line">mysql          	0:off	1:off	2:on	3:on	4:on	5:on	6:off</div></pre></td></tr></table></figure>
<h3 id="2-7-启动MySQL"><a href="#2-7-启动MySQL" class="headerlink" title="2.7 启动MySQL"></a>2.7 启动MySQL</h3><p>首先要切换到mysqladmin用户下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@Master mysql]<span class="comment"># su - mysqladmin</span></div><div class="line">[mysqladmin@Master ~]$ <span class="built_in">pwd</span></div><div class="line">/usr/<span class="built_in">local</span>/mysql</div><div class="line">[mysqladmin@Master ~]$ mv my.cnf my.cnf.bak</div></pre></td></tr></table></figure>
<p>执行启动脚本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">mysqladmin@Master ~]$ bin/mysqld_safe &amp;</div><div class="line">[1] 8966</div><div class="line">[mysqladmin@Master ~]$ 170925 16:33:51 mysqld_safe Logging to <span class="string">'/usr/local/mysql/data/hostname.err'</span>.</div><div class="line">170925 16:33:51 mysqld_safe Starting mysqld daemon with databases from /usr/<span class="built_in">local</span>/mysql/data</div><div class="line"></div><div class="line">[mysqladmin@Master ~]$</div></pre></td></tr></table></figure>
<p>验证启动进程</p>
<p>先切换到root用户下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@Master ~]<span class="comment"># ps -ef|grep mysqld</span></div><div class="line">514        4152   4122  0 13:51 pts/0    00:00:00 /bin/sh bin/mysqld_safe</div><div class="line">514        4795   4152  1 13:51 pts/0    00:00:03 /usr/<span class="built_in">local</span>/mysql/bin/mysqld --basedir=/usr/<span class="built_in">local</span>/mysql --datadir=/usr/<span class="built_in">local</span>/mysql/data --plugin-dir=/usr/<span class="built_in">local</span>/mysql/lib/plugin --<span class="built_in">log</span>-error=/usr/<span class="built_in">local</span>/mysql/data/hostname.err --pid-file=/usr/<span class="built_in">local</span>/mysql/data/hostname.pid --socket=/usr/<span class="built_in">local</span>/mysql/data/mysql.sock --port=3306</div><div class="line">root       4864   4819  0 13:55 pts/1    00:00:00 grep mysqld</div></pre></td></tr></table></figure>
<p>验证3306端口是否被监听</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@Master ~]<span class="comment"># netstat -tulnp | grep mysql</span></div><div class="line">tcp        0      0 :::3306                     :::*                        LISTEN      4795/mysqld</div></pre></td></tr></table></figure>
<p>查看mysql服务状态</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@Master ~]<span class="comment"># service mysql status</span></div><div class="line"> SUCCESS! MySQL running (4795)</div></pre></td></tr></table></figure>
<p>至此MySQL就安装成功了。yes! give me five!~~~ haha</p>
<h2 id="3-配置MySQL"><a href="#3-配置MySQL" class="headerlink" title="3.配置MySQL"></a>3.配置MySQL</h2><h3 id="3-1-登录"><a href="#3-1-登录" class="headerlink" title="3.1 登录"></a>3.1 登录</h3><p>使用mysql命令登录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line">[mysqladmin@Master ~]$ mysql</div><div class="line">Welcome to the MySQL monitor.  Commands end with ; or \g.</div><div class="line">Your MySQL connection id is 1</div><div class="line">Server version: 5.6.23-log MySQL Community Server (GPL)</div><div class="line"></div><div class="line">Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.</div><div class="line"></div><div class="line">Oracle is a registered trademark of Oracle Corporation and/or its</div><div class="line">affiliates. Other names may be trademarks of their respective</div><div class="line">owners.</div><div class="line"></div><div class="line">Type <span class="string">'help;'</span> or <span class="string">'\h'</span> <span class="keyword">for</span> <span class="built_in">help</span>. Type <span class="string">'\c'</span> to clear the current input statement.</div><div class="line"></div><div class="line">mysql&gt; use mysql;</div><div class="line">Database changed</div><div class="line">mysql&gt; update user <span class="built_in">set</span> password=password(<span class="string">'123456'</span>) <span class="built_in">where</span> user=<span class="string">'root'</span>;</div><div class="line">Query OK, 4 rows affected (0.00 sec)</div><div class="line">Rows matched: 4  Changed: 4  Warnings: 0</div><div class="line"></div><div class="line"></div><div class="line">mysql&gt; delete from user <span class="built_in">where</span> user=<span class="string">''</span>;</div><div class="line">Query OK, 2 rows affected (0.00 sec)</div><div class="line"></div><div class="line">mysql&gt; flush privileges;</div><div class="line"></div><div class="line"></div><div class="line">mysql&gt; select user,host from mysql.user;</div><div class="line">+------+-----------+</div><div class="line">| user | host      |</div><div class="line">+------+-----------+</div><div class="line">| root | 127.0.0.1 |</div><div class="line">| root | ::1       |</div><div class="line">| root | localhost |</div><div class="line">| root | master    |</div><div class="line">+------+-----------+</div><div class="line">4 rows <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</div></pre></td></tr></table></figure>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-10-04T13:43:52.487Z" itemprop="dateUpdated">2017-10-04 21:43:52</time>
</span><br>


        
        原始链接：<a href="/MySQL/MySQL--Source_Install.html" target="_blank" rel="external">http://xiejm.com/MySQL/MySQL--Source_Install.html</a>
        
    </div>
    <footer>
        <a href="http://xiejm.com">
            <img src="/img/avatar.jpg" alt="XieJM">
            XieJM
        </a>
    </footer>
</blockquote>

        


        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/MySQL/">MySQL</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://xiejm.com/MySQL/MySQL--Source_Install.html&title=《MySQL 5.6基于Linux源码编译安装》 — XieJM's Blog&pic=http://xiejm.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://xiejm.com/MySQL/MySQL--Source_Install.html&title=《MySQL 5.6基于Linux源码编译安装》 — XieJM's Blog&source=MySQL可以通过YUM或其他安装包快速安装，也可以下载源代码编译安装。从源代码编译安装MySQL是有好处，比如可以指定编译生产参数、优化编译、指定安装位..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://xiejm.com/MySQL/MySQL--Source_Install.html" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《MySQL 5.6基于Linux源码编译安装》 — XieJM's Blog&url=http://xiejm.com/MySQL/MySQL--Source_Install.html&via=http://xiejm.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://xiejm.com/MySQL/MySQL--Source_Install.html" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/Linux/Extended_VM Disk_In_ VMware.html" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">Linux Extended VM Disk In VMware</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/Hive/Hive--DDL.html" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">Hive--数据库和表</h4>
      </a>
    </div>
  
</nav>



    


<section class="comments" id="comments">
    <div id="disqus_thread"></div>
    <script>
    var disqus_shortname = 'true';
    lazyScripts.push('//' + disqus_shortname + '.disqus.com/embed.js')
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</section>













</article>



</div>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://xiejm.com/MySQL/MySQL--Source_Install.html&title=《MySQL 5.6基于Linux源码编译安装》 — XieJM's Blog&pic=http://xiejm.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://xiejm.com/MySQL/MySQL--Source_Install.html&title=《MySQL 5.6基于Linux源码编译安装》 — XieJM's Blog&source=MySQL可以通过YUM或其他安装包快速安装，也可以下载源代码编译安装。从源代码编译安装MySQL是有好处，比如可以指定编译生产参数、优化编译、指定安装位..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://xiejm.com/MySQL/MySQL--Source_Install.html" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《MySQL 5.6基于Linux源码编译安装》 — XieJM's Blog&url=http://xiejm.com/MySQL/MySQL--Source_Install.html&via=http://xiejm.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://xiejm.com/MySQL/MySQL--Source_Install.html" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: false };


</script>

<script src="/js/main.min.js?v=1.6.13"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="/js/search.min.js?v=1.6.13" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = 'XieJM's Blog';
            clearTimeout(titleTime);
        } else {
            document.title = 'XieJM's Blog';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
